<template>
  <div class="app-container">
    <el-row style="margin-bottom: 10px" :gutter="8">
      <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 12}" :xl="{span: 12}">
        <el-button class="pan-btn success-btn" v-if="isReregist" @click="submit" icon="el-icon-s-promotion" style="float: right;" type="success" size="mini">
          {{ isUpdate ? '重新发送' : ('发送至' + fromUserName) }}
        </el-button>
        <el-button class="pan-btn success-btn" v-if="sendAndGetBtn" @click="showGet" icon="el-icon-s-promotion" style="float: right;" type="success" size="mini">
          发送并取样
        </el-button>
        <el-button class="pan-btn success-btn" v-if="sendBtn && !sendAndGetBtn" @click="submit" icon="el-icon-s-promotion" style="float: right;" type="success" size="mini">
          发送
        </el-button>
        <el-tooltip effect="dark" :content="isFullLast ? '不填充' : '自动填充'" placement="top">
          <el-switch
            :disabled="fullLastDisabled"
            style="float: right;
            margin-right: 40px;
            margin-top: 8px;"
            v-model="isFullLast"
            @change="changeFullLast"
            active-color="#7cbd36"
            inactive-color="#ff4949"
            inactive-text="上一单">
          </el-switch>
        </el-tooltip>
      </el-col>
    </el-row>

    <el-row :gutter="8">
      <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 12}" :xl="{span: 12}">
        <el-card shadow="hover" class="card">
          <el-form ref="dataForm" :model="dataForm" label-width="80px">
            <el-form-item label="品名:" prop="productName">
              <span slot="label">品&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</span>
              <el-form :model="product" v-if="product != ''" :inline="true">
                <el-form-item>
                  {{product.productName}}
                </el-form-item>
                <el-form-item label="物料编码:">
                  {{product.productGmp}}
                </el-form-item>
                <el-form-item label="货品规格:">
                  <span v-html="product.productSpec"></span>
                </el-form-item>
                <el-form-item>
                  <el-button
                    :disabled="isReregist"
                    type="info"
                    class="pan-btn info-btn"
                    @click="showProductSelect"
                    size="mini">
                    重新选择
                  </el-button>
                </el-form-item>
              </el-form>
              <el-button
                v-if="product == ''"
                type="info"
                class="pan-btn info-btn"
                @click="showProductSelect"
                size="mini">
                请选择
              </el-button>
            </el-form-item>

            <el-form-item label="批号:" prop="batchNum">
              <span slot="label">批&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</span>
              <el-row style="width: 100%;">
                <el-col :span="isMerge ? 11 : 24">
                  <el-input id="batchNum" :disabled="isDisable" v-model="checkList.batchNumPrefix" @change="setBatchNum" placeholder="批号" size="small" style="width: 100%;" />
                </el-col>
                <div v-if="isMerge">
                  <el-col class="line" :offset="1" :span="1">-</el-col>
                  <el-col :span="11">
                    <el-input v-model="checkList.batchNumSuffix" @change="setBatchNum" placeholder="批号后缀" size="small" style="width: 100%;" />
                  </el-col>
                </div>
              </el-row>
            </el-form-item>

            <el-form-item v-if="product != ''" label="生产工序:" prop="procedureId">
              <el-select id="procedureId" :disabled="isDisable" v-model="dataForm.procedure" value-key="procedureId" @change="setProcedure" filterable placeholder="生产工序" style="width: 100%;" size="small">
                <el-option
                  v-for="item in procedureList"
                  :key="item.procedureId"
                  :label="item.procedureName"
                  :value="item">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="请验目的:" prop="isTest">
              <el-radio-group :disabled="isDisable" @change="changeIsTest" v-model="checkList.isTest" size="small">
                <el-radio-button :label="0">常规检验</el-radio-button>
                <el-radio-button :label="1">留样或稳考</el-radio-button>
                <el-radio-button :label="2">只稳考不留样</el-radio-button>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="包装规格:" prop="productPackSpec" v-if="!isHidePackSpec">
              <div v-if="productPackSpecList.length == 0" style="color: #F56C6C;">请添加此货品的包装规格</div>
              <el-select v-else id="productPackSpec2" v-model="checkList.productPackSpec" placeholder="包装规格" style="width: 100%;" size="small">
                <el-option v-for="item in productPackSpecList" :key="item.productPackSpecId" :label="item.productPackSpec" :value="item.productPackSpec" />
              </el-select>
            </el-form-item>

            <el-form-item label="请检项目:" prop="isAllTest" v-if="product != '' && checkList.isTest == 0">
              <div v-if="allItems.length == 0" style="color: #F56C6C;">请添加此货品的检验标准</div>
              <div v-else>
                <el-radio-group v-model="checkList.isAllTest" @change="changeItems" size="small">
                  <el-radio-button :label="0">全检</el-radio-button>
                  <el-radio-button :label="1">其他</el-radio-button>
                </el-radio-group>
                <el-button
                  style="margin-left: 20px;"
                  class="pan-btn info-btn"
                  type="info"
                  @click="showStandardDrawer"
                  size="mini">
                  查看项目
                </el-button>
              </div>
            </el-form-item>

            <el-form-item label="生产车间:" prop="workshopId">
              <el-select id="workshopId" v-model="dataForm.workshop" value-key="workshopId" @change="setWorkshop" filterable placeholder="生产车间" style="width: 100%;" size="small">
                <el-option
                  v-for="item in workshopList"
                  :key="item.workshopId"
                  :label="item.workshopName"
                  :value="item">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="生产日期:" prop="productionDate">
              <el-date-picker
                id="productionDate"
                v-model="zcList.productionDate"
                align="right"
                type="date"
                @change="setValidity"
                placeholder="选择日期"
                :picker-options="pickerOptions"
                style="width: 100%;"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd HH:mm:ss"
                size="small">
              </el-date-picker>
            </el-form-item>

            <el-form-item label="有效期至:" prop="validityDate" v-if="!isHideValidity">
              <el-date-picker
                id="validityDate"
                v-model="zcList.validityDate"
                align="right"
                type="date"
                placeholder="选择日期"
                style="width: 100%;"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd HH:mm:ss"
                size="small">
              </el-date-picker>
            </el-form-item>

            <el-form-item label="批量:" prop="batchQuantity">
              <span slot="label">批&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量:</span>
              <el-input id="batchQuantity" @change="setBatchQuantity" v-model="zcList.batchQuantity" placeholder="批量(数值)" size="small" style="width: 55%;">
                <el-select id="batchUnitId" @change="setBatchUnit" value-key="unitId" v-model="dataForm.batchUnit" slot="append" placeholder="单位" style="width: 100px;">
                  <el-option v-for="item in unitList" :key="item.unitId" :label="item.unitName" :value="item" />
                </el-select>
              </el-input>
            </el-form-item>

            <el-form-item label="产成品量:" prop="productionQuantity" v-if="!isHideProduction">
              <el-input id="productionQuantity" @change="setProductionQuantity" v-model="zcList.productionQuantity" placeholder="产成品量(数值)" size="small" style="width: 55%;">
                <el-select id="productionUnitId" @change="setProductionUnit" value-key="unitId" v-model="dataForm.productionUnit" slot="append" placeholder="单位" style="width: 100px;">
                  <el-option v-for="item in unitList" :key="item.unitId" :label="item.unitName" :value="item" />
                </el-select>
              </el-input>
            </el-form-item>

            <el-form-item label="请验日期:" prop="registCheckDate">
              <el-date-picker
                id="registCheckDate"
                v-model="checkList.registCheckDate"
                align="right"
                type="date"
                placeholder="选择日期"
                :picker-options="pickerOptions"
                style="width: 100%;"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd HH:mm:ss"
                size="small">
              </el-date-picker>
            </el-form-item>

            <el-form-item label="请验人:" prop="registCheckUserId">
              <span slot="label">请&nbsp;&nbsp;验&nbsp;&nbsp;人:</span>
              {{checkList.registCheckUserName}}
            </el-form-item>

            <el-form-item label="备注:" prop="remark">
              <span slot="label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</span>
              <el-input v-model="checkList.remark" placeholder="备注" size="small"/>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
      <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 12}" :xl="{span: 12}">
        <info-table
          v-if="infoVisible"
          ref="infotable" />
      </el-col>
    </el-row>

    <el-dialog
      title="取样"
      :visible.sync="getVisible"
      :before-close="closeGet"
      :close-on-click-modal="false"
      width="50%">
      注：此操作会记录在《取样台账记录》
      <el-row>
        <el-col :span="24">
          <el-card>
            <el-form>
              <el-form-item prop="getQuantity">
                <el-input v-model="checkList.getQuantity" placeholder="取样量(数值)">
                  <el-select @change="setGetUnit" value-key="unitId" v-model="checkList.getUnit" slot="append" placeholder="单位" style="width: 100px;">
                    <el-option v-for="item in unitList" :key="item.unitId" :label="item.unitName" :value="item" />
                  </el-select>
                </el-input>
                <el-input style="width: 100%; margin-top: 10px;" v-model="checkList.getRoom" placeholder="取样位置" />
                <el-date-picker
                  v-model="checkList.getDate"
                  align="right"
                  type="date"
                  placeholder="取样日期"
                  :clearable="false"
                  style="width: 100%; margin-top: 10px;"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
              </el-form-item>
            </el-form>
          </el-card>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeGet">取 消</el-button>
        <el-button class="pan-btn primary-btn" type="primary" @click="getOk">确 定</el-button>
    	</span>
    </el-dialog>

    <product-select
      @getProduct="getProduct"
      @showProductSelect="showProductSelect"
      :childDataForm="childDataForm"
      v-if="productSelectVisible" />

    <standard-drawer
      ref="standard"
      :childDataForm="childDataForm"
      @close="closeStandardDrawer"
      @getStandard="getStandard"
      v-if="standardDrawerVisible" />
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { CODE_OK } from '@/common/js/config'
  import { isBlank,parseTime,dateCompare } from '@/common/js/utils'
  import { isNumber } from '@/common/js/validate'
  import ProductSelect from '@/views/modules/base/product-select'
  import StandardDrawer from '@/views/modules/base/standard-drawer'
  import InfoTable from './info-table'
  import {
    getProcedureList,
    getWorkshopList,
    getUnitList,
    registCheck,
    registParasite,
    getRegistCheckInfo,
    getLastCheckForRegist,
    getHistoryByRegist
  } from '@/api/check'
  import { getStandardByProductId } from '@/api/standard'
  import { getProductPackSpecsByProductId,getProductProcessOne } from '@/api/product'
  export default {
    name: 'registcheck500',
    components: {
    	ProductSelect,StandardDrawer,InfoTable
    },
    data() {
      return {
        isFullLast: false,
        isReregist: false,
        isDisable: false,
        isUpdate: false,
        fromUserName: null,
        fromStatus: null,
        checkReturnId: null,
        productSelectVisible: false,
        standardDrawerVisible: false,
        getVisible: false,
        rag: false,
        productPackSpecList: [],
        allProcedureList: [],
        originalProcedureList: [],
        procedureList: [],
        workshopList: [],
        unitList: [],
        standard: '',
        allItems: [],
        items: [],
        checkList: {
          checkTypeId: 5,
          checkTypeName: '成品',
          isTest: '',
          isAllTest: '',
          isMerge: '',
          status: 1,
          getUnitId: '',
          getUnitName: '',
          registCheckDate: '',
          printCheckVersion: '00'
        },
        zcList: {
          procedureId: '',
          validityDate: ''
        },
        product: '',
        dataForm: {
          procedure: '',
          workshop: '',
          batchUnit: '',
          productionUnit: ''
        },
        childDataForm: '',
        infoVisible: false,
        infoData: {}
      }
    },
    created() {
      if (!isBlank(this.$route.query.checkId)) {
        this.isReregist = true
      }
      this.init()
      this.getZcInfo()
    },
    computed: {
      isMerge() {
        return this.product == '' ? false : this.product.haveProcess == 0 ? true : false
      },
      //是否显示产成品量和有效期等
      isHideValidity() {
        return this.checkList.isTest !== 1
      },
      isHideProduction () {
        return this.checkList.isTest !== 1
      },
      isHidePackSpec() {
        return this.dataForm.procedure.procedureName == '内包' || this.dataForm.procedure.procedureName == '灭菌' || this.dataForm.procedure.procedureName == '灯检'
      },
      ...mapGetters([
         'userInfo'
      ]),
      fullLastDisabled() {
        return this.allItems.length == 0 || this.product == '' || isBlank(this.zcList.procedureId) || this.isUpdate
      },
      sendBtn() {
        return !this.isReregist && !this.isUpdate && this.userInfo.roles.filter(r => {return r.roleName == '请验'}).length > 0
      },
      sendAndGetBtn() {
        return !this.isReregist && !this.isUpdate && (this.userInfo.roles.filter(r => {return r.roleName == '取样' || r.roleName == '信息' || r.roleName == '请取样'}).length > 0 || this.userInfo.userId == 1)
      }
    },
    methods: {
      init() {
        if (this.isReregist) {
          const params = {
            checkId: this.$route.query.checkId,
            content: 'zc'
          }
          getRegistCheckInfo(params).then(res => {
            if (res.code === CODE_OK) {
              this.fillData(res.info)
              this.setReregistInfo()
            }else{
              this.$message({
                message: res.msg,
                type: 'error',
                duration: 1000,
                onClose: () => {
                  window.history.go(-1)
                }
              })
            }
          })
        }else{
          this.setRegistInfo()
        }
      },
      setRegistInfo() {
        this.checkList.registCheckDepartmentId = this.userInfo.departmentId
        this.checkList.registCheckDepartmentName = this.userInfo.departmentName
        this.checkList.registCheckUserId = this.userInfo.userId
        this.checkList.registCheckUserName = this.userInfo.name
      },
      fillData(info) {
        let checkList = info.checkList
        let zcList = info.zcList
        //限制产成品量
        if (checkList.isTest == 1 && !isBlank(zcList.productionQuantity)) {
          zcList.productionQuantity = null
          this.dataForm.productionUnit = {
            unitId: 1,
            unitName: '盒'
          }
        }
        this.checkList = JSON.parse(JSON.stringify(checkList))
        this.zcList = JSON.parse(JSON.stringify(zcList))
        this.dataForm.procedure = {
          procedureId: zcList.procedureId,
          procedureName: zcList.procedureName
        }
        this.dataForm.workshop = {
          workshopId: zcList.workshopId,
          workshopName: zcList.workshopName,
        }
        this.dataForm.batchUnit = {
          unitId: zcList.batchUnitId,
          unitName: zcList.batchUnitName
        }
        if (this.isReregist) {
          this.getProduct(info.product)
          this.product.haveProcess = checkList.isMerge
          this.standard = info.standard
          this.isDisable = checkList.isMerge == 0 ? true : false
        }
        if (this.checkList.isTest == 0) {
          if (this.isFullLast && this.standard.insideInspectionStandardId != info.standard.insideInspectionStandardId) {
            if (checkList.isAllTest == 0) {
              this.checkList.isAllTest = checkList.isAllTest
              this.items = JSON.parse(JSON.stringify(this.allItems))
            }else{
              this.$message.error("标准已升级，请自己选择检验项目")
            }
          }else{
            this.checkList.isAllTest = checkList.isAllTest
            this.items = info.items
          }
        }else{
          this.checkList.isAllTest = 1
          this.items = []
        }
        this.setRegistInfo()
      },
      setReregistInfo() {
        if (this.$route.query.checkReturnId != 0) {
          this.fromUserName = this.$route.query.fromUserName
          this.fromStatus = this.$route.query.fromStatus
          this.checkReturnId = this.$route.query.checkReturnId
        }else{
          this.isUpdate = true
        }
      },
      getZcInfo() {
        getProcedureList().then(res => {
          if (res.code === CODE_OK) {
            this.procedureList = res.list
            this.allProcedureList = JSON.parse(JSON.stringify(this.procedureList))
          }else{
            this.$message.error(res.msg)
          }
        })
        getWorkshopList().then(res => {
          if (res.code === CODE_OK) {
            this.workshopList = res.list
          }else{
            this.$message.error(res.msg)
          }
        })
        getUnitList().then(res => {
          if (res.code === CODE_OK) {
            this.unitList = res.list
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      submit() {
        this.checkList.isMerge = this.isMerge ? 0 : 1
         if (this.formVerify()) {
           const data = {
             rag: this.rag,
             content: 'zc',
             fromStatus: this.fromStatus,
             checkReturnId: this.checkReturnId,
             checkList: this.checkList,
             zcList: this.zcList,
             product: this.product,
             standard: this.standard,
             items: this.items
           }
           registCheck(data).then(res => {
             if (res.code === CODE_OK) {
               this.$message({
                 message: '提交成功',
                 type: 'success',
                 duration: 1000,
                 onClose: () => {
                   window.history.go(-1)
                 }
               })
             }else if(res.code === 250) {
               let otherPackSpecs = res.otherLists.map(l => {
                 return l.productPackSpec
               }).join('、')
               this.$confirm('此批号已经存在其他包装规格('+otherPackSpecs+')的留样请验单和报告书，确定再次发起留样单?', '提示', {
                 confirmButtonText: '确定',
                 cancelButtonText: '取消',
                 type: 'warning'
               }).then(async () => {
                 data.checkList.isParasite = 0
                 data.firstRemainId = res.otherLists[0].checkId
                 registParasite(data).then(res => {
                   if (res.code === CODE_OK) {
                     this.$message({
                       message: '提交成功',
                       type: 'success',
                       duration: 1000,
                       onClose: () => {
                         window.history.go(-1)
                       }
                     })
                   }else{
                     this.$message.error(res.msg)
                   }
                 })
               }).catch(() => {})
             }else{
               this.$message.error(res.msg)
             }
           })
         }
      },
      changeFullLast() {
        if (this.isFullLast) {
          const params = {
            content: 'zc',
            productId: this.product.productId,
            procedureId: this.zcList.procedureId
          }
          getLastCheckForRegist(params).then(res => {
            if (res.code === CODE_OK) {
              this.fillData(res.info)
            }else{
              this.$message.error(res.msg)
              this.isFullLast = false
            }
          })
        }else{
          //初始化

        }
      },
      formVerify() {
        if (isBlank(this.product)) {
          this.$message.error('请选择货品')
          return false
        }
        if (isBlank(this.zcList.procedureId)) {
          this.$message.error('请选择工序')
          $("#procedureId").css({"border-color" : "#D08585"})
          return false
        }
        if (this.checkList.isTest === '') {
          this.$message.error('请选择请验目的')
          return false
        }
        $("#procedureId").removeAttr('style')
        if (!this.isHidePackSpec && isBlank(this.checkList.productPackSpec)) {
          this.$message.error('请选择或输入包装规格')
          if (this.productPackSpecList.length == 0) $("#productPackSpec1").css({"border-color" : "#D08585"})
          else $("#productPackSpec2").css({"border-color" : "#D08585"})
          return false
        }
        if (this.productPackSpecList.length == 0) $("#productPackSpec1").removeAttr('style')
        else $("#productPackSpec2").removeAttr('style')
        if (this.checkList.isTest == 0) {
          if (this.items.length == 0) {
            this.$message.error('请选择请验项目')
            return false
          }
        }
        if (isBlank(this.zcList.workshopId)) {
          this.$message.error('请选择生产车间')
          $("#workshopId").css({"border-color" : "#D08585"})
          return false
        }
        $("#workshopId").removeAttr('style')
        if (isBlank(this.checkList.batchNum)) {
          this.$message.error('请输入批号')
          $("#batchNum").css({"border-color" : "#D08585"})
          return false
        }
        $("#batchNum").removeAttr('style')
        if (isBlank(this.zcList.productionDate)) {
          this.$message.error('请选择生产日期')
          $("#productionDate").css({"border-color" : "#D08585"})
          return false
        }
        $("#productionDate").removeAttr('style')
        if (!this.isHideValidity && isBlank(this.zcList.validityDate)) {
          this.$message.error('请选择有效期')
          $("#validityDate").css({"border-color" : "#D08585"})
          return false
        }
        $("#validityDate").removeAttr('style')
        if (isBlank(this.zcList.batchQuantity)) {
          this.$message.error('请输入批量(数值)')
          $("#batchQuantity").css({"border-color" : "#D08585"})
          return false
        }
        $("#batchQuantity").removeAttr('style')
        if (isBlank(this.zcList.batchUnitId)) {
          this.$message.error('请选择批量(单位)')
          $("#batchUnitId").css({"border-color" : "#D08585"})
          return false
        }
        $("#batchUnitId").removeAttr('style')
        if (!this.isHideProduction && isBlank(this.zcList.productionQuantity)) {
          this.$message.error('请输入产成品量(数值)')
          $("#productionQuantity").css({"border-color" : "#D08585"})
          return false
        }
        $("#productionQuantity").removeAttr('style')
        if (!this.isHideProduction) {
          if (isBlank(this.zcList.productionUnitId)) {
            this.$message.error('请选择产成品量(单位)')
            $("#productionUnitId").css({"border-color" : "#D08585"})
            return false
          }
          if (this.zcList.productionUnitName != '盒' && this.zcList.workshopName.indexOf('大容量') < -1) {
            this.$message.error('产成品量必须以盒为单位，请严格按照成品报告要求填写(重要)')
            $("#productionUnitId").css({"border-color" : "#D08585"})
            return false
          }
        }
        $("#productionUnitId").removeAttr('style')
        if (isBlank(this.checkList.registCheckDate)) {
          this.$message.error('请选择请检日期')
          $("#registCheckDate").css({"border-color" : "#D08585"})
          return false
        }
        $("#registCheckDate").removeAttr('style')
        if (isBlank(this.checkList.registCheckDepartmentId) || isBlank(this.checkList.registCheckUserId)) {
          this.$message.error('登录过期,请刷新页面')
          return false
        }
        return true
      },
      changeItems() {
        if (this.checkList.isAllTest == 0) {
          this.items = JSON.parse(JSON.stringify(this.allItems))
        }else{
          this.items = []
          this.showStandardDrawer()
        }
      },
      showProductSelect() {
        this.childDataForm = {
          checkTypeId: this.checkList.checkTypeId
        }
      	this.productSelectVisible = !this.productSelectVisible
      },
      setValidity() {
        if (this.product.productValidity) {
          this.zcList.validityDate = this.calcValidity(this.zcList.productionDate,this.product.productValidity)
        }
      },
      setInfoData() {
        this.$refs.infotable.setInfoData(this.infoData)
      },
      showInfo() {
        const params = {
          productId: this.product.productId,
          batchNumPrefix: this.checkList.batchNumPrefix || null,
          checkTypeId: this.checkList.checkTypeId || null
        }
        getHistoryByRegist(params).then(res => {
          if (res.code === CODE_OK) {
            this.infoData.list = res.list
            if (!isBlank(this.checkList.batchNumPrefix)) {
              let pNamesNoMain = []
              let pNameMain = ''
              for (let l of this.infoData.list) {
                if (l.isTest == 1) {
                  pNameMain = l.procedureName
                }else{
                  pNamesNoMain.push(l.procedureName)
                }
              }
              this.infoData.isOneBatch = true
              this.infoData.procedures = this.originalProcedureList.map(p => {
                if (!p.isMain) {
                  if (pNamesNoMain.indexOf(p.procedureName) == -1) {
                    this.$set(p,'ok',false)
                  }else{
                    this.$set(p,'ok',true)
                  }
                }else if(pNameMain == p.procedureName){
                  this.$set(p,'ok', true)
                }else{
                  this.$set(p,'ok', false)
                }
                return p
              })
            }else{
              this.infoData.isOneBatch = false
              this.infoData.procedures = this.originalProcedureList
            }
            this.infoVisible = true
            this.$nextTick(() => {
              this.setInfoData()
            })
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      getProduct(product) {
        if (product.haveProcess == 1) {
          this.$message.error("请联系QC管理员(刘威)对此货品添加工序流程配置")
          return
        }
        if (product.productName == '硫酸阿米卡星' || product.productGmp == 'H02A') {
          this.$confirm('此货品需要确认名称?', '提示', {
            confirmButtonText: 'n=2',
            cancelButtonText: 'n=1.8',
            type: 'warning'
          }).then(() => {
            product.productName = product.productName + '(n=2)'
          }).catch(() => {
            product.productName = product.productName + '(n=1.8)'
          })
        }
        this.product = product
        this.originalProcedureList = []
        const params = {
          productId: product.productId
        }
        this.dataForm.workshop = {
          workshopId: product.workshopId,
          workshopName: product.workshopName
        }
        this.setWorkshop()
        this.initStandard()
        getProductPackSpecsByProductId(params).then(res => {
          if (res.code === CODE_OK) {
            this.productPackSpecList = res.productPackSpecs
            if (this.productPackSpecList.length == 0) {
              this.$message.error("请联系QA管理员(肖慧)添加此货品的包装规格")
            }
          }else{
            this.$message.error(res.msg)
          }
        })
        getStandardByProductId(params).then(res => {
          if (res.code === CODE_OK) {
            this.allItems = res.standard.items
            if (!this.isReregist) {
              this.standard = {
                insideInspectionStandardId: res.standard.insideInspectionStandardId,
                insideInspectionStandardNum: res.standard.insideInspectionStandardNum,
                nationInspectionStandardNum: res.standard.nationInspectionStandardNum,
                accordingToInside: res.standard.accordingToInside,
                accordingToNation: res.standard.accordingToNation
              }
            }
          }else{
            this.$message.error(res.msg)
          }
        })
        if (this.isMerge) {
          const params = {
            productId: product.productId
          }
          getProductProcessOne(params).then(res => {
            if (res.code === CODE_OK) {
              let procedureIdsArr = res.process.procedureIds.split(",")
              let tempProcedureList = []
              for (let id of procedureIdsArr) {
                for (let p of this.allProcedureList) {
                  if (id == p.procedureId) {
                    p.isMain = false
                    this.originalProcedureList.push(p)
                    if (tempProcedureList.indexOf(p) == -1) {
                      tempProcedureList.push(p)
                    }
                    break
                  }
                }
              }
              this.originalProcedureList[this.originalProcedureList.length-1].isMain = true
              this.procedureList = tempProcedureList
              this.showInfo()
            }else{
              this.$message.error(res.msg)
            }
          })
        }else{
          this.procedureList = JSON.parse(JSON.stringify(this.allProcedureList))
        }
      },
      showStandardDrawer() {
        this.childDataForm = {
          product: this.product,
          standard: this.standard,
          allItems: this.allItems,
          checkedItems: this.items
        }
        this.standardDrawerVisible = !this.standardDrawerVisible
      },
      closeStandardDrawer() {
        this.childDataForm = ''
        this.standardDrawerVisible = !this.standardDrawerVisible
      },
      getStandard(standardObj) {
        this.items = standardObj.checkedItems
        this.checkList.isAllTest = standardObj.isAllTest
      },
      initStandard() {
        this.standard = ''
        this.allItems = []
        this.items = []
        this.checkList.isAllTest = ''
      },
      //根据object赋值id和name
      changeIsTest() {
        if (this.checkList.isTest == 1 || this.checkList.isTest == 2) {
          this.checkList.isAllTest = 1
        }
      },
      setBatchNum() {
        this.showInfo()
        this.checkList.batchNum = isBlank(this.checkList.batchNumSuffix) ? this.checkList.batchNumPrefix : (this.checkList.batchNumPrefix + '-' + this.checkList.batchNumSuffix)
      },
      setProcedure() {
        this.zcList.procedureId = this.dataForm.procedure.procedureId
        this.zcList.procedureName = this.dataForm.procedure.procedureName
      },
      setWorkshop() {
        this.zcList.workshopId = this.dataForm.workshop.workshopId
        this.zcList.workshopName = this.dataForm.workshop.workshopName
      },
      setBatchQuantity() {
        if (!isNumber(this.zcList.batchQuantity)) {
          this.$message.error('请输入数值类型')
          this.zcList.batchQuantity = null
        }
      },
      setBatchUnit() {
        this.zcList.batchUnitId = this.dataForm.batchUnit.unitId
        this.zcList.batchUnitName = this.dataForm.batchUnit.unitName
      },
      setProductionQuantity() {
        if (!isNumber(this.zcList.productionQuantity)) {
          this.$message.error('请输入数值类型')
          this.zcList.productionQuantity = null
        }
      },
      setProductionUnit() {
        this.zcList.productionUnitId = this.dataForm.productionUnit.unitId
        this.zcList.productionUnitName = this.dataForm.productionUnit.unitName
      },
      setGetUnit() {
        this.checkList.getUnitId = this.checkList.getUnit.unitId
        this.checkList.getUnitName = this.checkList.getUnit.unitName
      },
      closeGet() {
        this.getVisible = false
      },
      getOk() {
        if (isBlank(this.checkList.getQuantity) ||isBlank(this.checkList.getUnitId) || isBlank(this.checkList.getUnitName)) {
          this.$message.error("取样量和单位不能为空")
          return
        }else if(isBlank(this.checkList.getDate)){
          this.$message.error("取样日期不能为空")
          return
        }
        // else if(!dateCompare(this.checkList.registCheckDate, this.checkList.getDate)){
        //   this.$message.error("取样日期必须晚于请验日期")
        //   return
        // }
        else{
          this.closeGet()
          this.rag = true
          this.submit()
        }
      },
      showGet() {
        if (isBlank(this.checkList.registCheckDate)) {
          this.$message.error('请选择请检日期')
          $("#registCheckDate").css({"border-color" : "#D08585"})
          return
        }
        this.$set(this.checkList,'getDate', JSON.parse(JSON.stringify(this.checkList.registCheckDate)))
        this.getVisible = true
      }
    }
  }
</script>

<style scoped>
  .el-form-item {
    margin-bottom: 8px !important;
  }
  .el-form-item__content .el-input-group {
    vertical-align: inherit !important;
  }
  >>> .el-input-group__append {
    border: 1px solid #ff0000;
  }
  >>> #batchUnitId::-webkit-input-placeholder {
    color: #ff0000;
  }
  >>> #batchUnitId::-moz-input-placeholder {
    color: #ff0000;
  }
  >>> #batchUnitId::-ms-input-placeholder {
    color: #ff0000;
  }
  >>> #productionUnitId::-webkit-input-placeholder {
    color: #ff0000;
  }
  >>> #productionUnitId::-moz-input-placeholder {
    color: #ff0000;
  }
  >>> #productionUnitId::-ms-input-placeholder {
    color: #ff0000;
  }
</style>
